#include <iostream>

using namespace std;

class point
{
public:
    point() {cout << "point::point()\n";}
    ~point() {cout << "point::~point()\n";}
    //point(double x=0.0, double y=0.0) {_x = x; _y = y;}

protected:
    double _x;    
    double _y;
};

class point3d
//class point3d : public point
{
public:
    point3d() : _p(0) { _p = new char[_size]; printf("point3d::point3d(), _p = 0x%08x, this=0x%08x\n", (int)(void*)_p, this);}
    ~point3d() { printf("point3d::~point3d(), _p = 0x%08x, this = 0x%08x\n", (int)(void*)_p, this); delete [] _p; }

protected:
    char * _p;
    static const int _size = 5;
};

class foo : public point3d
{
public:
    //foo() : _a(0) { cout << "foo::foo()\n"; }
    foo() { printf("foo::foo(), a = 0x%08x, this = 0x%08x\n", _a, this); }
    ~foo() { printf("foo::~foo(), a = 0x%08x, this = 0x%08x\n", _a, this); }

protected:
    int _a;
};

class base
{
public:
    base() {}
    virtual ~base() {}
    int _a;
    virtual void f() { printf("base::f()\n"); }
};

class derived : public base
{
public:
    derived() {}
    virtual ~derived() {}
    void f() { printf("derived::f()\n"); }
};

int main()
{
#if 0
    //void (point::*pmf)(void) = &point::point; 
    
    int size = 2;
   // point * pp = new point3d[size];
    point3d * pp = new foo[size];

    //delete [size+1]pp;
#if 0
    foo * pf = (foo*)pp;
    delete [] pf;
#else
    for (int ix = size-1; ix >= 0; ix --)
    {
	foo * fp = &((foo*)pp)[ix];
	delete fp;
    }
    //delete [] pp;
#endif
#endif
    base b;
    b.f();
    b.~base();
    new (&b) derived;
    b.f();

}
